package com.ym521.ymrouter.core;

import com.ym521.ymrouter.base.UniqueKeyTreeMap;
import com.ym521.ymrouter.facade.model.RouteMeta;
import com.ym521.ymrouter.facade.template.IInterceptor;
import com.ym521.ymrouter.facade.template.IProvider;
import com.ym521.ymrouter.facade.template.IRouteGroup;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Ym
 * E-mail: 2435970206@qq.com
 * createTime:2023/12/23
 * explain:
 */
public class Warehouse {
    // Cache route and metas
    static Map<String, Class<? extends IRouteGroup>> groupsIndex = new HashMap<>();
    static Map<String, RouteMeta> routes = new HashMap<>();

    // Cache provider
    static Map<Class, IProvider> providers = new HashMap<>();
    static Map<String, RouteMeta> providersIndex = new HashMap<>();

    // Cache interceptor
    static Map<Integer, Class<? extends IInterceptor>> interceptorsIndex = new UniqueKeyTreeMap<>("More than one interceptors use same priority [%s]");
    static List<IInterceptor> interceptors = new ArrayList<>();

    static void clear() {
        routes.clear();
        groupsIndex.clear();
        providers.clear();
        providersIndex.clear();
        interceptors.clear();
        interceptorsIndex.clear();
    }
}
